package com.gopay.scheduler.job;

import com.gopay.common.constants.fund.FundConstants;
import com.gopay.common.exception.FundException;
import com.gopay.common.util.DateUtils;
import com.gopay.remote.fundcps.service.FundCpsGenOrderService;
import com.gopay.scheduler.GopayBaseJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * 基金快赎对账JOB
 *
 * @author @author <a href="mailto:zookeeper1024@163.com">baiyunpeng</a>
 * @date 2017/12/27
 */
@Service("fundFastRedeemCheckAcctJob")
public class FundFastRedeemCheckAcctJob extends GopayBaseJob {
    private final static Logger LOGGER = LoggerFactory.getLogger(FundFastRedeemCheckAcctJob.class);

    @Resource(name = "fundCpsGenOrderService")
    private FundCpsGenOrderService fundCpsGenOrderService;

    @Override
    protected void doJobInternal() {
        String currDate = DateUtils.format(DateUtils.add(new Date(), Calendar.DATE, -6), "yyyyMMdd");
        String nextDate = DateUtils.format(DateUtils.add(new Date(), Calendar.DATE, 1), "yyyyMMdd");
        LOGGER.info("【基金活期宝快赎对账】 =====> 【业务开始】对账起始日期：{} —— {}", currDate, nextDate);
        try {
            fundCpsGenOrderService.fundFastRedeemCheckAcct(FundConstants.FUND_RTFUND, currDate, nextDate);
        } catch (FundException e) {
            LOGGER.error("【基金活期宝快赎对账】 =====> 执行异常！", e);
        }
        LOGGER.info("【基金活期宝快赎对账】 <===== 【业务结束】完成，执行起始日期：{} —— {}", currDate, nextDate);
    }
}
